package hva.team2.viavia;

import hva.team2.viavia.tools.CItyDownloader;
import hva.team2.viavia.tools.City;
import hva.team2.viavia.tools.CityParser;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class test extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        final TextView tv = (EditText) findViewById(R.id.editText);
        tv.setText("https://dl.dropboxusercontent.com/u/44269514/ExAlicante.xml");
        final Button button = (Button) findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                final TextView tv = (EditText) findViewById(R.id.editText);
                CItyDownloader cd = new CItyDownloader();


                cd.setFileName(tv.getText().toString());
                cd.setUrl(tv.getText().toString());
                cd.run();
                while(cd.isAlive()){
                    try {
                        wait(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                CityParser cp = new CityParser();
                City alc = cp.parse("/data/data/hva.team2.viavia/sample.txt");

                EditText et = (EditText) findViewById(R.id.editText2);
                et.setText(alc.toString());


            }
        });
    }


    
}
